using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Navigation;
using Microsoft.Phone.Controls;
using Microsoft.Phone.Shell;
using LyonMag.Resources;
using Windows.Phone.Networking;
using System.Xml.Linq;
using System.Windows.Media;
using System.Collections.ObjectModel;
using GoogleAds;
using System.Windows.Threading;
using System.Diagnostics;
using System.Globalization;
using Microsoft.Phone.Net.NetworkInformation;
namespace LyonMag
{
    public partial class MainPage : PhoneApplicationPage
    {
        private DispatcherTimer dispatcherTimer = new System.Windows.Threading.DispatcherTimer();

        string url = "http://www.lyonmag.com/win8/get_news";

        string lastmovies = "http://cinema.egdigital.fr/media/xml/affiche.xml";
        string othermvies = "http://cinema.egdigital.fr/media/xml/cinema.xml";
        private App app = App.Current as App;
        List<LyonMag.Homepageclass.Person> obj_list = new List<LyonMag.Homepageclass.Person>();
        string refresh = "Actual";
        // Constructor
        ObservableCollection<Homepageclass.Person> obj_newListForum = new ObservableCollection<Homepageclass.Person>();
        Stopwatch stopWatch = new Stopwatch();
        string hellodata = string.Empty;
        private InterstitialAd interstitialAd;

        public MainPage()
        {
            try
            {
                InitializeComponent();
                app.lst_Home.Clear();
                //MessageBox.Show("version 30");
                get_Data();
                adsss.Height = 0;

                stkad.Margin = new Thickness(0, 640, 0, 0);
                interstitialAd = new InterstitialAd("ca-app-pub-5292432475881872/3887048137");
                AdRequest adRequest = new AdRequest();
                // Enable test ads.
                adRequest.ForceTesting = true;

                interstitialAd.ReceivedAd +=interstitialAd_ReceivedAd; 
                interstitialAd.LoadAd(adRequest);

          

            }
            catch (Exception ex)
            {

                if (NetworkInterface.GetIsNetworkAvailable() == true)
                {
                    // MessageBox.Show(NetworkInterface.GetIsNetworkAvailable().ToString());
                }
                else
                {
                    MessageBox.Show("Internet Not Availabe", "LyonMag", MessageBoxButton.OK);
                }
                ex.Message.ToString();
            }


        }
        private void dispatcherTimer_Tick(object sender, EventArgs e)
        {
            if (stopWatch.ElapsedMilliseconds > Convert.ToInt64(30000))
            {
                stopWatch.Stop();
                stopWatch.Reset();
                dispatcherTimer.Stop();
                adsss.Visibility = Visibility.Collapsed;
                stkad.Background = new SolidColorBrush(Colors.Transparent);
                stkad.Margin = new Thickness(0, 640, 0, 0);
            }
            else
            {
                //btnCloseadd.Margin = new Thickness(0, 20, 0, 0);
                //  stkad.Margin = new Thickness(0, 558, 0, 0);
                // stkad.Background = new SolidColorBrush(Colors.Black);
            }
        }
        public void get_filedata()
        {
            try
            {
                if (refresh != "Actual")
                {
                    app.lst_files.Clear();
                    WebClient wc_files = new WebClient();
                    wc_files.DownloadStringAsync(new Uri(url));
                    wc_files.DownloadStringCompleted += wc_files_DownloadStringCompleted;
                }
            }
            catch (Exception ex)
            {
                ex.Message.ToString();
            }
        }

        void wc_files_DownloadStringCompleted(object sender, DownloadStringCompletedEventArgs e)
        {
            try
            {
                try
                {

                    lstFiles.ItemsSource = null;
                    string peopleXMLPath = e.Result.ToString();
                    XDocument loadedData = XDocument.Parse(peopleXMLPath);

                    var data = from query in loadedData.Elements("feed").Elements("article")
                               select new LyonMag.Homepageclass.Person
                               {
                                   Title = (string)query.Element("title"),
                                   AppImage = (string)query.Element("thumb"),
                                   Header = (string)query.Element("text"),
                                   Category = (string)query.Element("category"),
                                   Date = (string)query.Element("date"),
                                   Comments = (string)query.Element("nb_comments"),
                                   Id = (string)query.Element("id"),
                                   Thumbtitle = (string)query.Element("thumb_title"),
                                   Home_comments = new List<Homepageclass.HomeComments>(from sz in query.Elements("comments").Elements("comment")
                                                                                        select new Homepageclass.HomeComments()
                                                                                  {
                                                                                      Comment_id = (string)sz.Element("comment_id"),
                                                                                      Comment_text = (string)sz.Element("comment_text"),
                                                                                      Comment_name = "Déposé par : " + " " + (string)sz.Element("comment_name") + " " + "le " + DateTime.Parse((string)sz.Element("comment_date")).ToString("dd MM yyyy  HH:mm:ss"),
                                                                                      Comment_date = (string)sz.Element("comment_date")
                                                                                  }).ToList()

                               };

                    foreach (LyonMag.Homepageclass.Person readldata in data)
                    {



                        string diff = string.Empty;
                        string hello = string.Empty;
                        DateTime dt = DateTime.Parse(readldata.Date);
                        string d = Convert.ToDateTime(GetCountryTime("France")).Date.ToString();
                        System.TimeSpan diff1 = Convert.ToDateTime(GetCountryTime("France")).Date - dt.Date;
                        if (diff1.Days == 1)
                        {
                            hello = "Hier à ";
                            app.datafiles.Add(new Homepageclass.Person() { Thumbtitle = readldata.Thumbtitle, Fulldate = readldata.Date, Fulltitle = readldata.Title, Id = readldata.Id, Fulltext = readldata.Header, Comments = readldata.Comments, Category = readldata.Category.ToUpper(), AppImage = readldata.AppImage, Date = hello + dt.ToString("HH:mm"), Header = readldata.Header, Title = readldata.Title, Home_comments = readldata.Home_comments });
                            app.lst_files.Add(new Homepageclass.Person() { Thumbtitle = readldata.Thumbtitle, Fulldate = readldata.Date, Fulltitle = readldata.Title, Id = readldata.Id, Fulltext = readldata.Header, Comments = readldata.Comments, Category = readldata.Category.ToUpper(), AppImage = readldata.AppImage, Date = hello + dt.ToString("HH:mm"), Header = readldata.Header, Title = readldata.Title, Home_comments = readldata.Home_comments });
                        }
                        else if (diff1.Days == 2)
                        {
                            hello = "Le  ";
                            app.lst_files.Add(new Homepageclass.Person() { Thumbtitle = readldata.Thumbtitle, Fulldate = readldata.Date, Fulltitle = readldata.Title, Id = readldata.Id, Fulltext = readldata.Header, Comments = readldata.Comments, Category = readldata.Category.ToUpper(), AppImage = readldata.AppImage, Date = hello + DateTime.Parse(readldata.Date).ToString("dd MM yyyy") + " à " + DateTime.Parse(readldata.Date).ToString("HH:mm"), Header = readldata.Header, Title = readldata.Title, Home_comments = readldata.Home_comments });
                        }
                        else if (diff1.Days >= 0)
                        {
                            hello = "Aujourd'hui à ";
                            app.datafiles.Add(new Homepageclass.Person() { Thumbtitle = readldata.Thumbtitle, Fulldate = readldata.Date, Fulltitle = readldata.Title, Id = readldata.Id, Fulltext = readldata.Header, Comments = readldata.Comments, Category = readldata.Category.ToUpper(), AppImage = readldata.AppImage, Date = hello + dt.ToString("HH:mm"), Header = readldata.Header, Title = readldata.Title, Home_comments = readldata.Home_comments });
                            app.lst_files.Add(new Homepageclass.Person() { Thumbtitle = readldata.Thumbtitle, Fulldate = readldata.Date, Fulltitle = readldata.Title, Id = readldata.Id, Fulltext = readldata.Header, Comments = readldata.Comments, Category = readldata.Category.ToUpper(), AppImage = readldata.AppImage, Date = hello + dt.ToString("HH:mm"), Header = readldata.Header, Title = readldata.Title, Home_comments = readldata.Home_comments });
                        }
                        else
                        {
                            hello = " ";
                            app.datafiles.Add(new Homepageclass.Person() { Thumbtitle = readldata.Thumbtitle, Fulldate = readldata.Date, Fulltitle = readldata.Title, Id = readldata.Id, Fulltext = readldata.Header, Comments = readldata.Comments, Category = readldata.Category.ToUpper(), AppImage = readldata.AppImage, Date = hello + dt.ToString("HH:mm"), Header = readldata.Header, Title = readldata.Title, Home_comments = readldata.Home_comments });
                            app.lst_files.Add(new Homepageclass.Person() { Thumbtitle = readldata.Thumbtitle, Fulldate = readldata.Date, Fulltitle = readldata.Title, Id = readldata.Id, Fulltext = readldata.Header, Comments = readldata.Comments, Category = readldata.Category.ToUpper(), AppImage = readldata.AppImage, Date = hello + dt.ToString("HH:mm"), Header = readldata.Header, Title = readldata.Title, Home_comments = readldata.Home_comments });
                        }


                        //obj_list.Add(new LyonMag.Homepageclass.Person() { Thumbtitle = readldata.Thumbtitle, Fulldate = readldata.Date, Fulltitle = readldata.Title, Id = readldata.Id, Fulltext = readldata.Header, Comments = readldata.Comments, Category = readldata.Category.ToUpper(), AppImage = readldata.AppImage, Date = "Aujourd'hui à " + dt.ToString("HH:mm"), Header = readldata.Header + "...", Title = readldata.Title, Home_comments = readldata.Home_comments });
                    }
                    lstFiles.Visibility = Visibility.Visible;
                    lstForum.Visibility = Visibility.Collapsed;
                    lstAct.Visibility = Visibility.Collapsed;
                    lstFiles.ItemsSource = app.lst_files;
                    btnProgress.Visibility = Visibility.Collapsed;
                    app.savefiles();

                }
                catch (Exception ex)
                {
                    //MessageBox.Show(ex.Message.ToString());


                    lstFiles.Visibility = Visibility.Visible;
                    lstFiles.ItemsSource = obj_list;
                    btnProgress.Visibility = Visibility.Collapsed;
                    lstForum.Visibility = Visibility.Collapsed;
                    if (ex.Message.ToString() == "An exception occurred during the operation, making the result invalid.  Check InnerException for exception details.")
                    {
                        MessageBox.Show("Internet Not Availabe", "LyonMag", MessageBoxButton.OK);
                        lstAct.ItemsSource = app.data;
                        lstForum.ItemsSource = app.dataforum;
                        lstFiles.ItemsSource = app.datafiles;
                        btnProgress.Visibility = Visibility.Collapsed;
                    }
                }
            }
            catch (Exception ex)
            {
                ex.Message.ToString();
            }
        }
        public void get_Data()
        {
            try
            {

                WebClient wc = new WebClient();
                wc.DownloadStringAsync(new Uri("http://www.lyonmag.com/win8/get_news"));
                wc.DownloadStringCompleted += wc_DownloadStringCompleted;
            }
            catch (Exception ex)
            {
                ex.Message.ToString();
            }
        }

        protected override void OnNavigatedFrom(NavigationEventArgs e)
        {

        }
        protected override void OnNavigatedTo(NavigationEventArgs e)
        {
            try
            {

                if (NetworkInterface.GetIsNetworkAvailable() == true)
                {
                   // MessageBox.Show(NetworkInterface.GetIsNetworkAvailable().ToString());
                }
                else 
                {
                    MessageBox.Show("Internet Not Availabe", "LyonMag", MessageBoxButton.OK);
                    lstAct.ItemsSource = app.data;
                    lstForum.ItemsSource = app.dataforum;
                    lstFiles.ItemsSource = app.datafiles;
                    btnProgress.Visibility = Visibility.Collapsed;
                }
                //if (adsss.Visibility == Visibility.Visible)
                //{ //adsss.IsHitTestVisible==true
                //    stkad.Margin = new Thickness(0, 558, 0, 0);
                //    //stkad.Margin = new Thickness(0, 640, 0, 0);
                //    stkad.Background = new SolidColorBrush(Colors.Black);
                //}
                //else
                //{
                //    stkad.Background = new SolidColorBrush(Colors.Transparent);
                // //   stkad.Margin = new Thickness(0, 640, 0, 0);


                //}
                btnCloseadd.Tap += btnCloseadd_Tap;

            }
            catch (Exception ex)
            {
                ex.Message.ToString();
                btnCloseadd.Tap += btnCloseadd_Tap;
            }
        }
        protected override void OnBackKeyPress(System.ComponentModel.CancelEventArgs e)
        {
            try
            {
                Application.Current.Terminate();
            }
            catch (Exception ex)
            {
                ex.Message.ToString();
            }
        }




        void wc_DownloadStringCompleted(object sender, DownloadStringCompletedEventArgs e)
        {
            try
            {
                if (refresh == "Actual")
                {
                    app.lst_Home.Clear();
                    List<Homepageclass.Person> obj_list = new List<Homepageclass.Person>();
                    string peopleXMLPath = e.Result.ToString();
                    XDocument loadedData = XDocument.Parse(peopleXMLPath);
                    //stklatest.Background = new SolidColorBrush(Colors.Gray);
                    var data = from query in loadedData.Elements("feed").Elements("article")
                               select new Homepageclass.Person
                               {
                                   Title = (string)query.Element("title"),
                                   AppImage = (string)query.Element("thumb"),
                                   Header = (string)query.Element("text"),
                                   Category = (string)query.Element("category"),
                                   Date = (string)query.Element("date"),
                                   Comments = (string)query.Element("nb_comments"),
                                   Id = (string)query.Element("id"),
                                   Fulltext = (string)query.Element("text"),
                                   Thumbtitle = (string)query.Element("thumb_title"),
                                   Home_comments = new List<Homepageclass.HomeComments>(from sz in query.Elements("comments").Elements("comment")
                                                                                        select new Homepageclass.HomeComments()
                                                                                   {
                                                                                       Comment_id = (string)sz.Element("comment_id"),
                                                                                       Comment_text = (string)sz.Element("comment_text"),
                                                                                       Comment_name = "Déposé par : " + " " + (string)sz.Element("comment_name") + " " + "le " + DateTime.Parse((string)sz.Element("comment_date")).ToString("dd MM yyyy  HH:mm:ss"),
                                                                                       Comment_date = (string)sz.Element("comment_date")

                                                                                   }).ToList()



                               };

                    foreach (LyonMag.Homepageclass.Person readldata in data)
                    {

                        app.lst_Home.Add(new LyonMag.Homepageclass.Person() { Thumbtitle = readldata.Thumbtitle, Fulltext = readldata.Fulltext, Id = readldata.Id, Comments = readldata.Comments, Category = readldata.Category, AppImage = readldata.AppImage, Date = readldata.Date, Header = readldata.Header, Title = readldata.Title, Home_comments = readldata.Home_comments });
                        app.data.Add((new LyonMag.Homepageclass.Person() { Thumbtitle = readldata.Thumbtitle, Fulltext = readldata.Fulltext, Id = readldata.Id, Comments = readldata.Comments, Category = readldata.Category, AppImage = readldata.AppImage, Date = readldata.Date, Header = readldata.Header, Title = readldata.Title, Home_comments = readldata.Home_comments }));
                    }
                    app.savehome();
                    lstFiles.Visibility = Visibility.Collapsed;
                    lstAct.ItemsSource = app.lst_Home;
                    lstAct.Visibility = Visibility.Visible;
                    btnProgress.Visibility = Visibility.Collapsed;
                    stklatest.Tap += stklatest_Tap;
                }
            }
            catch (Exception ex)
            {

                MessageBox.Show("Internet Not Availabe", "LyonMag", MessageBoxButton.OK);
                lstAct.ItemsSource = app.data;
                lstForum.ItemsSource = app.dataforum;
                lstFiles.ItemsSource = app.datafiles;
                btnProgress.Visibility = Visibility.Collapsed;
               // MessageBox.Show(ex.Message.ToString());
            }
        }

        private void stkFileInfo_Tap(object sender, System.Windows.Input.GestureEventArgs e)
        {
            refresh = "stkFile";
            add.Visibility = Visibility.Collapsed;
            stkFilesradio.Visibility = Visibility.Visible;
            btnForum.Visibility = Visibility.Visible;
            stkCinemaRadio.Visibility = Visibility.Collapsed;
            lstAct.Visibility = Visibility.Collapsed;
            lstForum.Visibility = Visibility.Collapsed;
            lstFiles.Visibility = Visibility.Visible;
            lstCinema.Visibility = Visibility.Collapsed;
            stkFileInfo.Background = new SolidColorBrush(Colors.Gray);
            stkCinema.Background = new SolidColorBrush(Colors.Black);
            stklatest.Background = new SolidColorBrush(Colors.Black);

            stkForums.Background = new SolidColorBrush(Colors.Black);
            stkLesPlus.Background = new SolidColorBrush(Colors.Black);

            lstAct.ItemsSource = "";
            url = "http://www.lyonmag.com/win8/get_wires";
            btnProgress.Visibility = Visibility.Visible;
            get_filedata();
        }

        private void stkForums_Tap(object sender, System.Windows.Input.GestureEventArgs e)
        {
            refresh = "forum";
            add.Visibility = Visibility.Visible;
            btnForum.Visibility = Visibility.Collapsed;
            stkCinemaRadio.Visibility = Visibility.Collapsed;
            stkForums.Background = new SolidColorBrush(Colors.Gray);
            stkFilesradio.Visibility = Visibility.Collapsed;
            stkCinema.Background = new SolidColorBrush(Colors.Black);
            stklatest.Background = new SolidColorBrush(Colors.Black);
            lstAct.Visibility = Visibility.Collapsed;
            lstFiles.Visibility = Visibility.Collapsed;
            lstForum.Visibility = Visibility.Visible;
            lstCinema.Visibility = Visibility.Collapsed;

            stkLesPlus.Background = new SolidColorBrush(Colors.Black);
            stkFileInfo.Background = new SolidColorBrush(Colors.Black);
            lstAct.ItemsSource = "";
            url = "http://www.lyonmag.com/win8/get_forum";
            btnProgress.Visibility = Visibility.Visible;

            get_forum();

        }
        private void OnAdReceived(object sender, AdEventArgs e)
        {
            try
            {
                adsss.Height = 77;

                stkad.Margin = new Thickness(0, 558, 0, 0);
                adsss.Visibility = Visibility.Visible;
                btnCloseadd.Margin = new Thickness(0, 0, 0, 0);
                // stkad.Margin = new Thickness(0, 640, 0, 0);
                //sent to lyon
                stkad.Background = new SolidColorBrush(Colors.Black);
                dispatcherTimer.Tick += new EventHandler(dispatcherTimer_Tick);
                dispatcherTimer.Interval = new TimeSpan(0, 0, 1);
                stopWatch.Start();
                dispatcherTimer.Start();

            }
            catch (Exception ex)
            {
                // stkad.Margin = new Thickness(0, 558, 0, 0);
            }


        }

        private void interstitialAd_ReceivedAd(object sender, AdEventArgs e)
        {
            try
            {
                System.Diagnostics.Debug.WriteLine("Ad received successfully");
                interstitialAd.ShowAd();

            }
            catch (Exception ex)
            {
                // stkad.Margin = new Thickness(0, 558, 0, 0);
            }


        }
        private void OnFailedToReceiveAd(object sender, AdErrorEventArgs e)
        {
            try
            {
                // adsss.Visibility = Visibility.Collapsed;
                // MessageBox.Show("no AD");
            }
            catch (Exception ex)
            {

            }
        }

        private void stkCinema_Tap(object sender, System.Windows.Input.GestureEventArgs e)
        {
            refresh = "Cinema";
            add.Visibility = Visibility.Collapsed;
            stkCinema.Background = new SolidColorBrush(Colors.Gray);
            stkFilesradio.Visibility = Visibility.Collapsed;
            stklatest.Background = new SolidColorBrush(Colors.Black);
            lstFiles.Visibility = Visibility.Collapsed;
            lstForum.Visibility = Visibility.Collapsed;
            lstAct.Visibility = Visibility.Collapsed;
            lstCinema.Visibility = Visibility.Visible;
            stkCinemaRadio.Visibility = Visibility.Visible;
            btnForum.Visibility = Visibility = Visibility.Visible;
            stkForums.Background = new SolidColorBrush(Colors.Black);
            stkLesPlus.Background = new SolidColorBrush(Colors.Black);
            stkFileInfo.Background = new SolidColorBrush(Colors.Black);
            lstAct.ItemsSource = "";
            url = "http://cinema.egdigital.fr/media/xml/prog.xml";
            btnProgress.Visibility = Visibility.Visible;
            get_CinemeData();
        }

        public void get_CinemeData()
        {
            try
            {
                stkFilesradio.Visibility = Visibility.Collapsed;
                lstFiles.Visibility = Visibility.Collapsed;
                lstForum.Visibility = Visibility.Collapsed;
                lstAct.Visibility = Visibility.Collapsed;
                lstCinema.Visibility = Visibility.Collapsed;
                WebClient wc_cinema = new WebClient();

                wc_cinema.DownloadStringAsync(new Uri(url));
                wc_cinema.DownloadStringCompleted += wc_cinema_DownloadStringCompleted;
            }
            catch (Exception ex)
            {
                ex.Message.ToString();
            }
        }
        //get  forumdat
        public void get_forum()
        {

            try
            {
                lstForum.Visibility = Visibility.Collapsed;
                WebClient wc_forum = new WebClient();
                wc_forum.DownloadStringAsync(new Uri(url));
                wc_forum.DownloadStringCompleted += wc_forum_DownloadStringCompleted;
            }
            catch (Exception ex)
            {
                ex.Message.ToString();
            }
        }

        void wc_forum_DownloadStringCompleted(object sender, DownloadStringCompletedEventArgs e)
        {
            try
            {
                try
                {
                    app.lst_Forum.Clear();

                    string peopleXMLPath = e.Result.ToString();
                    XDocument loadedData = XDocument.Parse(peopleXMLPath);

                    string cid = string.Empty;
                    var data = from query in loadedData.Elements("feed").Elements("article")
                               select new Cinema.Person_Files
                               {
                                   Id = (string)query.Element("id"),
                                   Title = (string)query.Element("title"),
                                   AppImage = (string)query.Element("thumb"),
                                   Header = (string)query.Element("text"),
                                   Category = (string)query.Element("category"),
                                   Date = (string)query.Element("date"),
                                   Thumbtitle = (string)query.Element("thumb_title"),
                                   Color_name = (string)query.Element("color_name"),
                                   Commentscount =  (string)query.Element("nb_comments"),

                                   forum_comments = new List<Cinema.ForumComments>(from sz in query.Elements("comments").Elements("comment")
                                                                                   select new Cinema.ForumComments()
                                                                          {


                                                                              Comment_id = (string)sz.Element("comment_id"),

                                                                              Comment_name = (string)sz.Element("comment_name"),
                                                                              Comment_text = (string)sz.Element("comment_text"),
                                                                              Comment_date = (string)sz.Element("comment_date")

                                                                          }).ToList()




                               };



                    foreach (Cinema.Person_Files readldata in data)
                    {
                        String diff2 = string.Empty;
                        string hours = string.Empty;
                        string days = string.Empty;
                        string minutes = string.Empty;


                        string dateTime = Convert.ToDateTime(GetCountryTime("France")).ToString();
                       // string dt = Convert.ToDateTime(readldata.forum_comments.Last().Comment_date.ToString()).ToString();

                       //string datecurrent = DateTime.Now.ToString("MM/dd/yy H:mm:ss");
                       //string second = dt;


                        System.TimeSpan diff1 = DateTime.Parse(DateTime.Now.ToString()) - DateTime.Parse(readldata.forum_comments.Last().Comment_date);
                        //System.TimeSpan diff1 = Convert.ToDateTime(dateTime) - Convert.ToDateTime(dt);
                     // ////  System.TimeSpan diff1 =Convert.ToDateTime( dateTime) -Convert.ToDateTime( dt);
                        diff2 = diff1.Minutes.ToString();
                        hours = diff1.Hours.ToString();
                        days = diff1.Days.ToString();
                        minutes = diff1.Minutes.ToString();

                     
                      
                        if (Convert.ToInt32(hours) < 1 && Convert.ToInt32(days) < 1)
                        {
                            if (Convert.ToInt32( readldata.Commentscount) == 1)
                            {
                              
                                app.lst_Forum.Add(new Cinema.Person_Files() { Color_name = readldata.Color_name, Thumbtitle = readldata.Thumbtitle, Fulldate = readldata.Date, Commentscount = "  " + "[ " + readldata.Commentscount + "message ]", Category = readldata.Category, AppImage = readldata.AppImage, Date = " " + "Il y a " + minutes.Replace("-","") + " minutes ", Header = readldata.Header, Title = readldata.Title, forum_comments = readldata.forum_comments, Id = readldata.Id });
                                app.dataforum.Add(new Cinema.Person_Files() { Color_name = readldata.Color_name, Thumbtitle = readldata.Thumbtitle, Fulldate = readldata.Date, Commentscount = readldata.Commentscount, Category = readldata.Category, AppImage = readldata.AppImage, Date = " " + "Il y a " + days + "  jours ", Header = readldata.Header, Title = readldata.Title, forum_comments = readldata.forum_comments, Id = readldata.Id });
                                // app.lst_Forum.Add(new Cinema.Person_Files() {Color_name=readldata.Color_name, Thumbtitle = readldata.Thumbtitle, Fulldate = readldata.Date, Commentscount = readldata.Commentscount, Category = readldata.Category, AppImage = readldata.AppImage, Date = " " + "Il y a " + days + "  jours ", Header = readldata.Header, Title = readldata.Title, forum_comments = readldata.forum_comments, Id = readldata.Id });
                            }
                            else
                            {
                                app.lst_Forum.Add(new Cinema.Person_Files() { Color_name = readldata.Color_name, Thumbtitle = readldata.Thumbtitle, Fulldate = readldata.Date, Commentscount =  "  " + "[ " + readldata.Commentscount + "messages ]", Category = readldata.Category, AppImage = readldata.AppImage, Date = " " + "Il y a " + minutes.Replace("-","") + " minutes ", Header = readldata.Header, Title = readldata.Title, forum_comments = readldata.forum_comments, Id = readldata.Id });
                                app.dataforum.Add(new Cinema.Person_Files() { Color_name = readldata.Color_name, Thumbtitle = readldata.Thumbtitle, Fulldate = readldata.Date, Commentscount = readldata.Commentscount, Category = readldata.Category, AppImage = readldata.AppImage, Date = " " + "Il y a " + days + "  jours ", Header = readldata.Header, Title = readldata.Title, forum_comments = readldata.forum_comments, Id = readldata.Id });
                            }

                            }
                        else if (Convert.ToInt32(hours) >= 1 && Convert.ToInt32(days) == 0)
                        {
                            if (Convert.ToInt32(readldata.Commentscount) == 1)
                            {

                                app.lst_Forum.Add(new Cinema.Person_Files() { Color_name = readldata.Color_name, Thumbtitle = readldata.Thumbtitle, Fulldate = readldata.Date, Commentscount = "  " + "[ " + readldata.Commentscount + "message ]", Category = readldata.Category, AppImage = readldata.AppImage, Date = " " + "Il y a " + hours.Replace("-","") + " heures" , Header = readldata.Header, Title = readldata.Title, forum_comments = readldata.forum_comments, Id = readldata.Id });
                                app.dataforum.Add(new Cinema.Person_Files() { Color_name = readldata.Color_name, Thumbtitle = readldata.Thumbtitle, Fulldate = readldata.Date, Commentscount = readldata.Commentscount, Category = readldata.Category, AppImage = readldata.AppImage, Date = " " + "Il y a " + days + "  jours ", Header = readldata.Header, Title = readldata.Title, forum_comments = readldata.forum_comments, Id = readldata.Id });
                            }
                            else
                            {
                                app.lst_Forum.Add(new Cinema.Person_Files() { Color_name = readldata.Color_name, Thumbtitle = readldata.Thumbtitle, Fulldate = readldata.Date, Commentscount =  "  " + "[ " + readldata.Commentscount + "messages ]", Category = readldata.Category, AppImage = readldata.AppImage, Date = " " + "Il y a " + hours.Replace("-","") + " heures" , Header = readldata.Header, Title = readldata.Title, forum_comments = readldata.forum_comments, Id = readldata.Id });
                                app.dataforum.Add(new Cinema.Person_Files() { Color_name = readldata.Color_name, Thumbtitle = readldata.Thumbtitle, Fulldate = readldata.Date, Commentscount = readldata.Commentscount, Category = readldata.Category, AppImage = readldata.AppImage, Date = " " + "Il y a " + days + "  jours ", Header = readldata.Header, Title = readldata.Title, forum_comments = readldata.forum_comments, Id = readldata.Id });
                            }
                              }
                        else if (Convert.ToInt32(days) > 1)
                        {
                            if (Convert.ToInt32(readldata.Commentscount) == 1)
                            {
                                app.lst_Forum.Add(new Cinema.Person_Files() { Color_name = readldata.Color_name, Thumbtitle = readldata.Thumbtitle, Fulldate = readldata.Date, Commentscount =  "  " + "[ " + readldata.Commentscount + "message ]", Category = readldata.Category, AppImage = readldata.AppImage, Date = " " + "Il y a " + " Hier ", Header = readldata.Header, Title = readldata.Title, forum_comments = readldata.forum_comments, Id = readldata.Id });
                                app.dataforum.Add(new Cinema.Person_Files() { Color_name = readldata.Color_name, Thumbtitle = readldata.Thumbtitle, Fulldate = readldata.Date, Commentscount = readldata.Commentscount, Category = readldata.Category, AppImage = readldata.AppImage, Date = " " + "Il y a " + days + "  jours ", Header = readldata.Header, Title = readldata.Title, forum_comments = readldata.forum_comments, Id = readldata.Id });

                            }
                            else
                            {

                                app.lst_Forum.Add(new Cinema.Person_Files() { Color_name = readldata.Color_name, Thumbtitle = readldata.Thumbtitle, Fulldate = readldata.Date, Commentscount =  "  " + "[ " + readldata.Commentscount + "messages ]", Category = readldata.Category, AppImage = readldata.AppImage, Date = " " + "Il y a " + " Hier ", Header = readldata.Header, Title = readldata.Title, forum_comments = readldata.forum_comments, Id = readldata.Id });
                                app.dataforum.Add(new Cinema.Person_Files() { Color_name = readldata.Color_name, Thumbtitle = readldata.Thumbtitle, Fulldate = readldata.Date, Commentscount = readldata.Commentscount, Category = readldata.Category, AppImage = readldata.AppImage, Date = " " + "Il y a " + days + "  jours ", Header = readldata.Header, Title = readldata.Title, forum_comments = readldata.forum_comments, Id = readldata.Id });

                            }
                        }
                        else
                        {
                            if (Convert.ToInt32(readldata.Commentscount) == 1)
                            {

                                app.lst_Forum.Add(new Cinema.Person_Files() { Color_name = readldata.Color_name, Thumbtitle = readldata.Thumbtitle, Fulldate = readldata.Date, Commentscount =  "  " + "[ " + readldata.Commentscount + "message ]", Category = readldata.Category, AppImage = readldata.AppImage, Date = " " + "Il y a " + days + "  jours ", Header = readldata.Header, Title = readldata.Title, forum_comments = readldata.forum_comments, Id = readldata.Id });
                                app.dataforum.Add(new Cinema.Person_Files() { Color_name = readldata.Color_name, Thumbtitle = readldata.Thumbtitle, Fulldate = readldata.Date, Commentscount = readldata.Commentscount, Category = readldata.Category, AppImage = readldata.AppImage, Date = " " + "Il y a " + days + "  jours ", Header = readldata.Header, Title = readldata.Title, forum_comments = readldata.forum_comments, Id = readldata.Id });
                            }
                            else
                            {

                                app.lst_Forum.Add(new Cinema.Person_Files() { Color_name = readldata.Color_name, Thumbtitle = readldata.Thumbtitle, Fulldate = readldata.Date, Commentscount = "  " + "[ " + readldata.Commentscount + "messages ]", Category = readldata.Category, AppImage = readldata.AppImage, Date = " " + "Il y a " + days + "  jours ", Header = readldata.Header, Title = readldata.Title, forum_comments = readldata.forum_comments, Id = readldata.Id });
                                app.dataforum.Add(new Cinema.Person_Files() { Color_name = readldata.Color_name, Thumbtitle = readldata.Thumbtitle, Fulldate = readldata.Date, Commentscount = readldata.Commentscount, Category = readldata.Category, AppImage = readldata.AppImage, Date = " " + "Il y a " + days + "  jours ", Header = readldata.Header, Title = readldata.Title, forum_comments = readldata.forum_comments, Id = readldata.Id });
                            }
                            }
                        app.saveforum();
                       
                    }

                    lstForum.ItemsSource = app.lst_Forum;
                    lstFiles.Visibility = Visibility.Collapsed;
                    lstForum.Visibility = Visibility.Visible;
                    btnProgress.Visibility = Visibility.Collapsed;
                }
                catch (Exception ex)
                {
                    lstForum.ItemsSource = app.lst_Forum;
                    btnProgress.Visibility = Visibility.Collapsed;
                    lstForum.Visibility = Visibility.Visible;

                    if (ex.Message.ToString() == "An exception occurred during the operation, making the result invalid.  Check InnerException for exception details.")
                    {
                        MessageBox.Show("Internet Not Availabe", "LyonMag", MessageBoxButton.OK);
                        lstAct.ItemsSource = app.data;
                        lstForum.ItemsSource = app.dataforum;
                        lstFiles.ItemsSource = app.datafiles;
                        btnProgress.Visibility = Visibility.Collapsed;
                    }
                }
            }
            catch (Exception ex)
            {
                ex.Message.ToString();
            }
        }


        void wc_cinema_DownloadStringCompleted(object sender, DownloadStringCompletedEventArgs e)
        {
            try
            {
                lstCinema.ItemsSource = "";
                string peopleXMLPath = e.Result.ToString();
                XDocument loadedData = XDocument.Parse(peopleXMLPath);
                lstCinema.Visibility = Visibility.Visible;
                var data = from query in loadedData.Elements("semaine").Elements("film")
                           select new Cinema.CinemaClass
                           {
                               Title = (string)query.Element("titre"),
                               AppImage = "http://cinema.egdigital.fr/media/images/" + (string)query.Element("vignette"),
                               Header = (string)query.Element("texte"),
                               Realisateur = (string)query.Element("realisateur"),
                               Fulltext = (string)query.Element("texte"),
                               Date = (string)query.Element("sortie"),
                               Id = (string)query.Element("id"),
                               Distributeur = (string)query.Element("distributeur"),
                               Duree = (string)query.Element("duree"),
                               Acteur = (string)query.Element("acteur"),

                               Genres = (string)query.Element("genres").Element("genre"),

                               cinema_details = new List<Cinema.innercinema>(from sz in query.Elements("cinema").Elements("cine")
                                                                             select new Cinema.innercinema()
                                                                               {
                                                                                   Cine_horaires = (string)sz.Element("cine_horaires"),
                                                                                   Cine_nom = (string)sz.Element("cine_nom"),
                                                                                   Cinemaid = (string)sz.Element("cine_id")

                                                                               }).ToList()




                           };
                app.lst_Cinema_comment.Clear();
                foreach (Cinema.CinemaClass dat in data)
                {
                    app.lst_Cinema_comment.Add(new Cinema.CinemaClass() { Genres = dat.Genres, Acteur = dat.Acteur, Duree = dat.Duree, Fulltext = dat.Fulltext, Distributeur = dat.Distributeur, Category = dat.Category, Id = dat.Id, AppImage = dat.AppImage, Date = DateTime.Parse(dat.Date).ToString("dd MM yyyy"), cinema_details = dat.cinema_details, Commentscount = dat.Commentscount, Header = dat.Header, Realisateur = dat.Realisateur, Text = dat.Text, Title = dat.Title });
                }
                lstAct.Visibility = Visibility.Collapsed;
                stkFilesradio.Visibility = Visibility.Collapsed;
                lstCinema.ItemsSource = app.lst_Cinema_comment;
                lstCinema.Visibility = Visibility.Visible;
                lstForum.Visibility = Visibility.Collapsed;
                btnProgress.Visibility = Visibility.Collapsed;
            }
            catch (Exception ex)
            {
                ex.Message.ToString();
            }
        }

        private void stkLesPlus_Tap(object sender, System.Windows.Input.GestureEventArgs e)
        {

            NavigationService.Navigate(new Uri("/Socail.xaml", UriKind.RelativeOrAbsolute));
        }

        private void lstAct_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            try
            {
                LyonMag.Homepageclass.Person p = new LyonMag.Homepageclass.Person();
                p = lstAct.SelectedItem as LyonMag.Homepageclass.Person;
                lstAct.SelectedIndex = -1;
                NavigationService.Navigate(new Uri("/Detail.xaml?title=" + p.Title + "&header=" + p.Fulltext + "&imageurl=" + p.AppImage + "&date=" + p.Date + "&category=" + p.Category + "&id=" + p.Id + "&commentscount=" + p.Comments + "&thumb=" + p.Thumbtitle + "", UriKind.RelativeOrAbsolute));

            }
            catch (Exception ex)
            {
                ex.Message.ToString();
            }
        }

        private void stklatest_Tap(object sender, System.Windows.Input.GestureEventArgs e)
        {
            refresh = "Actual";
            add.Visibility = Visibility.Collapsed;
            stklatest.Background = new SolidColorBrush(Colors.Gray);
            stkCinema.Background = new SolidColorBrush(Colors.Black);
            stkForums.Background = new SolidColorBrush(Colors.Black);
            stkLesPlus.Background = new SolidColorBrush(Colors.Black);
            stkFileInfo.Background = new SolidColorBrush(Colors.Black);
            btnForum.Visibility = Visibility.Visible;
            stkFilesradio.Visibility = Visibility.Collapsed;
            stkCinemaRadio.Visibility = Visibility.Collapsed;
            lstAct.Visibility = Visibility.Visible;
            lstForum.Visibility = Visibility.Collapsed;
            lstFiles.Visibility = Visibility.Collapsed;
            lstCinema.Visibility = Visibility.Collapsed;
            lstAct.ItemsSource = "";
            url = "http://www.lyonmag.com/win8/get_news";
            btnProgress.Visibility = Visibility.Visible;
            get_Data();
        }

        private void lstFiles_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            try
            {
                LyonMag.Homepageclass.Person p = new LyonMag.Homepageclass.Person();

                p = lstFiles.SelectedItem as LyonMag.Homepageclass.Person;
                if (p == null)
                {
                    // lstFiles.SelectedIndex = -1;
                    NavigationService.Navigate(new Uri("/FileDetail.xaml?title=" + p.Fulltitle + "&header=" + p.Fulltext + "&imageurl=" + p.AppImage + "&date=" + p.Fulldate + "&category=" + p.Category + "&id=" + p.Id + "&commentscount=" + p.Comments + "&thumbtitle=" + p.Thumbtitle + "", UriKind.RelativeOrAbsolute));
                }
                else
                {
                    //  lstFiles.SelectedIndex = -1;
                    NavigationService.Navigate(new Uri("/FileDetail.xaml?title=" + p.Fulltitle + "&header=" + p.Fulltext + "&imageurl=" + p.AppImage + "&date=" + p.Fulldate + "&category=" + p.Category + "&id=" + p.Id + "&commentscount=" + p.Comments + "&thumbtitle=" + p.Thumbtitle + "", UriKind.RelativeOrAbsolute));
                }

            }
            catch (Exception ex)
            {
                ex.Message.ToString();
            }

        }

        private void RadioButton_Checked(object sender, RoutedEventArgs e)
        {

        }

        private void lstForum_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            try
            {
                Cinema.Person_Files obj = new Cinema.Person_Files();
                obj = lstForum.SelectedItem as Cinema.Person_Files;
                lstForum.SelectedIndex = -1;
                NavigationService.Navigate(new Uri("/UserComments.xaml?id=" + obj.Id, UriKind.RelativeOrAbsolute));
            }
            catch (Exception ex)
            {
                ex.Message.ToString();
            }
        }

        private void lstCinema_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            try
            {
                Cinema.CinemaClass obj = new Cinema.CinemaClass();
                obj = lstCinema.SelectedItem as Cinema.CinemaClass;
                lstCinema.SelectedIndex = -1;
                NavigationService.Navigate(new Uri("/CinemaDetail.xaml?id=" + obj.Id, UriKind.RelativeOrAbsolute));
            }
            catch (Exception ex)
            {
                ex.Message.ToString();
            }
        }

        private void btnForum_Click(object sender, RoutedEventArgs e)
        {
            stkForums.Background = new SolidColorBrush(Colors.Gray);
            btnForum.Visibility = Visibility.Collapsed;
            stkCinema.Background = new SolidColorBrush(Colors.Black);
            stklatest.Background = new SolidColorBrush(Colors.Black);
            lstAct.Visibility = Visibility.Collapsed;
            lstFiles.Visibility = Visibility.Collapsed;
            lstForum.Visibility = Visibility.Visible;
            lstCinema.Visibility = Visibility.Collapsed;
            stkLesPlus.Background = new SolidColorBrush(Colors.Black);
            stkFileInfo.Background = new SolidColorBrush(Colors.Black);
            lstAct.ItemsSource = "";
            url = "http://www.lyonmag.com/win8/get_forum";
            btnProgress.Visibility = Visibility.Visible;

            get_forum();
        }

        private void radio_Checked(object sender, RoutedEventArgs e)
        {

        }

        private void radioTous_Checked(object sender, RoutedEventArgs e)
        {
            try
            {
                obj_newListForum.Clear();
                if (radioTous.IsChecked == true)
                {

                    get_filedata();

                }
            }
            catch (Exception ex)
            {
                ex.Message.ToString();
            }
        }

        private void RADIOPOLITE_Checked(object sender, RoutedEventArgs e)
        {
            try
            {
                if (RADIOPOLITE.IsChecked == true)
                {

                    obj_newListForum.Clear();
                    url = "http://www.lyonmag.com/win8/get_wires_by_category/1";
                    get_filedata();

                }

            }
            catch (Exception ex)
            {
                ex.Message.ToString();
            }
        }

        private void radiojudi_Checked(object sender, RoutedEventArgs e)
        {

            obj_newListForum.Clear();
            url = "http://www.lyonmag.com/win8/get_wires_by_category/2";
            get_filedata();

        }

        private void radiosocial_Checked(object sender, RoutedEventArgs e)
        {


            obj_newListForum.Clear();
            url = "http://www.lyonmag.com/win8/get_wires_by_category/3";
            get_filedata();

        }

        private void LesRadio_Checked(object sender, RoutedEventArgs e)
        {
            obj_newListForum.Clear();
            url = "http://www.lyonmag.com/win8/get_wires_by_category/2";
            get_filedata();

        }

        private void alaRadio_Checked(object sender, RoutedEventArgs e)
        {
            if (alaRadio.IsChecked == true)
            {
                url = lastmovies;
                get_CinemeData();

            }
        }

        private void imgRefresh_Tap(object sender, System.Windows.Input.GestureEventArgs e)
        {
            if (refresh == "stkFile")
            {
                btnProgress.Visibility = Visibility.Visible;
                stkFilesradio.Visibility = Visibility.Visible;
                stkCinemaRadio.Visibility = Visibility.Collapsed;
                lstAct.Visibility = Visibility.Collapsed;
                lstForum.Visibility = Visibility.Collapsed;
                lstFiles.Visibility = Visibility.Collapsed;
                lstCinema.Visibility = Visibility.Collapsed;
                stkFileInfo.Background = new SolidColorBrush(Colors.Gray);
                stkCinema.Background = new SolidColorBrush(Colors.Black);
                stklatest.Background = new SolidColorBrush(Colors.Black);

                stkForums.Background = new SolidColorBrush(Colors.Black);
                stkLesPlus.Background = new SolidColorBrush(Colors.Black);

                lstAct.ItemsSource = "";
                url = "http://www.lyonmag.com/win8/%20get_wires";
                radioTous.IsChecked = true;
                get_filedata();
            }
            else if (refresh == "Actual")
            {
                stklatest.Background = new SolidColorBrush(Colors.Gray);
                stkCinema.Background = new SolidColorBrush(Colors.Black);
                stkForums.Background = new SolidColorBrush(Colors.Black);
                stkLesPlus.Background = new SolidColorBrush(Colors.Black);
                stkFileInfo.Background = new SolidColorBrush(Colors.Black);
                stkFilesradio.Visibility = Visibility.Collapsed;
                lstAct.Visibility = Visibility.Visible;
                lstForum.Visibility = Visibility.Collapsed;
                lstFiles.Visibility = Visibility.Collapsed;
                lstCinema.Visibility = Visibility.Collapsed;
                lstAct.ItemsSource = "";
                url = "http://www.lyonmag.com/win8/get_news";
                btnProgress.Visibility = Visibility.Visible;
                get_Data();
            }
            else if (refresh == "forum")
            {
                // refresh = "forum";
                btnProgress.Visibility = Visibility.Visible;
                lstForum.Visibility = Visibility.Collapsed;
                stkCinemaRadio.Visibility = Visibility.Collapsed;
                stkForums.Background = new SolidColorBrush(Colors.Gray);
                stkFilesradio.Visibility = Visibility.Collapsed;
                stkCinema.Background = new SolidColorBrush(Colors.Black);
                stklatest.Background = new SolidColorBrush(Colors.Black);
                lstAct.Visibility = Visibility.Collapsed;
                lstFiles.Visibility = Visibility.Collapsed;
                lstForum.Visibility = Visibility.Visible;
                lstCinema.Visibility = Visibility.Collapsed;
                stkLesPlus.Background = new SolidColorBrush(Colors.Black);
                stkFileInfo.Background = new SolidColorBrush(Colors.Black);
                lstAct.ItemsSource = "";
                url = "http://www.lyonmag.com/win8/get_forum";
                btnProgress.Visibility = Visibility.Visible;

                get_forum();
            }
            else
            {
                btnProgress.Visibility = Visibility.Visible;
                stkCinema.Background = new SolidColorBrush(Colors.Gray);
                stkFilesradio.Visibility = Visibility.Collapsed;
                stklatest.Background = new SolidColorBrush(Colors.Black);
                lstFiles.Visibility = Visibility.Collapsed;
                lstForum.Visibility = Visibility.Collapsed;
                lstAct.Visibility = Visibility.Collapsed;
                lstCinema.Visibility = Visibility.Visible;
                stkCinemaRadio.Visibility = Visibility.Visible;

                stkForums.Background = new SolidColorBrush(Colors.Black);
                stkLesPlus.Background = new SolidColorBrush(Colors.Black);
                stkFileInfo.Background = new SolidColorBrush(Colors.Black);
                lstAct.ItemsSource = "";
                url = "http://cinema.egdigital.fr/media/xml/prog.xml";
                btnProgress.Visibility = Visibility.Visible;
                get_CinemeData();

            }
        }

        private void Fait_Checked(object sender, RoutedEventArgs e)
        {
            obj_newListForum.Clear();
            url = "http://www.lyonmag.com/win8/get_wires_by_category/36";
            get_filedata();
        }

        private void trans_Checked(object sender, RoutedEventArgs e)
        {
            obj_newListForum.Clear();
            url = "http://www.lyonmag.com/win8/get_wires_by_category/14";
            get_filedata();
        }

        private void OLe_Checked(object sender, RoutedEventArgs e)
        {
            obj_newListForum.Clear();
            url = "http://www.lyonmag.com/win8/get_wires_by_category/12";
            get_filedata();
        }

        private void Edu_Checked(object sender, RoutedEventArgs e)
        {
            obj_newListForum.Clear();
            url = "http://www.lyonmag.com/win8/get_wires_by_category/47";
            get_filedata();
        }

        private void Eco_Checked(object sender, RoutedEventArgs e)
        {
            obj_newListForum.Clear();
            url = "http://www.lyonmag.com/win8/get_wires_by_category/4";
            get_filedata();

        }

        private void Social_Checked(object sender, RoutedEventArgs e)
        {
            try
            {
                obj_newListForum.Clear();
                url = "http://www.lyonmag.com/win8/get_wires_by_category/3";
                get_filedata();


            }
            catch (Exception ex)
            {
                ex.Message.ToString();
            }
        }

        private void Sports_Checked(object sender, RoutedEventArgs e)
        {
            try
            {
                obj_newListForum.Clear();
                url = "http://www.lyonmag.com/win8/get_wires_by_category/5";
                get_filedata();
            }
            catch (Exception ex)
            {
                ex.Message.ToString();
            }
        }

        private void ASVEL_Checked(object sender, RoutedEventArgs e)
        {
            obj_newListForum.Clear();
            url = "http://www.lyonmag.com/win8/get_wires_by_category/9";
            get_filedata();
        }

        private void Cul_Checked(object sender, RoutedEventArgs e)
        {
            obj_newListForum.Clear();
            url = "http://www.lyonmag.com/win8/get_wires_by_category/11";
            get_filedata();
        }

        private void End_Checked(object sender, RoutedEventArgs e)
        {
            obj_newListForum.Clear();
            url = "http://www.lyonmag.com/win8/get_wires_by_category/13";
            get_filedata();
        }

        private void Peo_Checked(object sender, RoutedEventArgs e)
        {
            obj_newListForum.Clear();
            url = "http://www.lyonmag.com/win8/get_wires_by_category/6";
            get_filedata();

        }

        private void San_Checked(object sender, RoutedEventArgs e)
        {
            obj_newListForum.Clear();
            url = "http://www.lyonmag.com/win8/get_wires_by_category/34";
            get_filedata();
        }

        private void Et_Checked(object sender, RoutedEventArgs e)
        {
            obj_newListForum.Clear();
            url = "http://www.lyonmag.com/win8/get_wires_by_category/37";
            get_filedata();

        }

        private void High_Checked(object sender, RoutedEventArgs e)
        {
            obj_newListForum.Clear();
            url = "http://www.lyonmag.com/win8/get_wires_by_category/35";
            get_filedata();
        }

        private void meto_Checked(object sender, RoutedEventArgs e)
        {
            obj_newListForum.Clear();
            url = "http://www.lyonmag.com/win8/get_wires_by_category/7";
            get_filedata();
        }

        private void envi_Checked(object sender, RoutedEventArgs e)
        {
            obj_newListForum.Clear();
            url = "http://www.lyonmag.com/win8/get_wires_by_category/33";
            get_filedata();
        }

        private void contri_Checked(object sender, RoutedEventArgs e)
        {
            obj_newListForum.Clear();
            url = "http://www.lyonmag.com/win8/get_wires_by_category/46";
            get_filedata();
        }

        private void Edi_Checked(object sender, RoutedEventArgs e)
        {
            obj_newListForum.Clear();
            url = "http://www.lyonmag.com/win8/get_wires_by_category/45";
            get_filedata();
        }

        private void btnCloseadd_Tap(object sender, System.Windows.Input.GestureEventArgs e)
        {
            if (adsss.Visibility == Visibility.Visible)
            {



                adsss.Visibility = Visibility.Collapsed;
                stkad.Background = new SolidColorBrush(Colors.Transparent);
                btnCloseadd.Margin = new Thickness(0, 80, 0, 0);


            }
            else
            {
                adsss.Visibility = Visibility.Visible;
                btnCloseadd.Margin = new Thickness(0, 0, 0, 0);
                stkad.Background = new SolidColorBrush(Colors.Transparent);
                dispatcherTimer.Tick += new EventHandler(dispatcherTimer_Tick);
                dispatcherTimer.Interval = new TimeSpan(0, 0, 1);
                stopWatch.Start();
                dispatcherTimer.Start();
            }
        }

        private void OLe_Checked_1(object sender, RoutedEventArgs e)
        {

        }

        private void societe_Checked(object sender, RoutedEventArgs e)
        {
            obj_newListForum.Clear();
            url = "http://www.lyonmag.com/win8/get_wires_by_category/8";
            get_filedata();
        }

        private void ApplicationBarIconButton_Click(object sender, EventArgs e)
        {
            try
            {
                ApplicationBar.IsVisible = false;
                App.appSettingsGuid["accoutid"] = "test";
                App.appSettingsGuid.Save();
            }
            catch (Exception ex)
            {
                ApplicationBar.IsVisible = false;
                App.appSettingsGuid["accoutid"] = "test";
                App.appSettingsGuid.Save();
                ex.Message.ToString();
            }
        }

        private void add_Tap(object sender, System.Windows.Input.GestureEventArgs e)
        {
            NavigationService.Navigate(new Uri("/postforum.xaml", UriKind.RelativeOrAbsolute));
        }
        private string GetCountryTime(string country)
        {
            DateTime gmt = default(DateTime);
            System.DateTime value = default(System.DateTime);
            gmt = DateTime.Now.AddMinutes(-330);

            switch (country)
            {
                case "India":
                case "Sri Lanka":
                    return DateTime.Now.ToString();
                case "United Kingdom":
                case "Portugal":
                case "Sierra Leone":
                case "Senegal":
                case "Morocco":
                case "Mali":
                    return gmt.ToString();
                case "France":
                case "Spain":
                case "Slovenia":
                case "Slovakia":
                case "Poland":
                case "Nigeria":
                case "Niger":
                case "Hungary":
                case "Denmark":
                case "Czech Republic":
                    return gmt.AddMinutes(120).ToString();
                case "Botswana":
                case "Moldova":
                case "South Africa":
                case "Malawi":
                case "Lithuania":
                case "Libya":
                case "Turkey":
                case "Finland":
                case "Egypt":
                    return gmt.AddMinutes(120).ToString(); 
                case "Bahrain":
                case "Somalia":
                case "Saudi Arabia":
                case "Russia":
                case "Qatar":
                case "Sudan":
                case "Madagascar":
                case "Iraq":
                    return gmt.AddMinutes(180).ToString();
                case "Iran":
                    return gmt.AddMinutes(220).ToString();
                case "Armenia":
                case "Seychelles":
                case "Reunion":
                case "Oman":
                case "Mauritius":
                case "United Arab Emirates":
                case "Georgia":
                case "Azerbaijan":
                    return gmt.AddMinutes(240).ToString();
                case "Afghanistan":
                    return gmt.AddMinutes(270).ToString();
                case "Pakistan":
                case "Maldives":
                case "Kyrgyzstan":
                    return gmt.AddMinutes(300).ToString();
                case "Nepal":
                    return gmt.AddMinutes(345).ToString();
                case "Bangladesh":
                case "Kazakhstan":
                    return gmt.AddMinutes(360).ToString();
                case "Myanmar":
                    return gmt.AddMinutes(390).ToString();
                case "Cambodia":
                case "Laos":
                    return gmt.AddMinutes(420).ToString();
                case "Philippines":
                case "Malaysia":
                case "Hong Kong":
                case "China":
                    return gmt.AddMinutes(480).ToString();
                case "Japan":
                case "Korea":
                    return gmt.AddMinutes(540).ToString();
                case "Micronesia":
                    return gmt.AddMinutes(720).ToString();
                case "Papua New Guinea":
                case "Australia":
                    return gmt.AddMinutes(600).ToString();
                case "New Caledonia":
                    return gmt.AddMinutes(660).ToString();
                case "New Zealand":
                case "Fiji":
                    return gmt.AddMinutes(720).ToString();
                case "Argentina":
                case "Brazil":
                    return gmt.AddMinutes(-180).ToString();
                case "Cuba":
                    return gmt.AddMinutes(-300).ToString();
                case "Aruba":
                case "Paraguay":
                case "Netherlands Antilles":
                case "Barbados":
                case "Chile":
                case "Dominican Republic":
                case "Guyana":
                    return gmt.AddMinutes(-240).ToString();
                case "Bahamas":
                    return gmt.AddMinutes(-240).ToString();
                case "Peru":
                case "Panama":
                case "Jamaica":
                case "Haiti":
                case "Colombia":
                case "Canary Islands":
                    return gmt.AddMinutes(-300).ToString();
                case "Bhutan":
                    return gmt.AddMinutes(360).ToString();
                case "Belize":
                case "Mexico":
                case "Honduras":
                case "Canada":
                    return gmt.AddMinutes(-360).ToString();
                case "Nicaragua":
                    return gmt.AddMinutes(-300).ToString();

                case "United States Of America":
                    return gmt.AddMinutes(-480).ToString();
                case "French Polynesia":
                    return gmt.AddMinutes(720).ToString();
                case "Samoa":
                    return gmt.AddMinutes(-660).ToString();
                case "Singapore":
                    return gmt.AddMinutes(480).ToString();
                case "Slovak Republic":
                    return gmt.AddMinutes(60).ToString();
                case "Solomon Islands":
                    return gmt.AddMinutes(660).ToString();
                case "St Helena":
                    return gmt.AddMinutes(0).ToString();
                case "St Kitts & Nevia":
                    return gmt.AddMinutes(-240).ToString();
                case "St Lucia":
                    return gmt.AddMinutes(-240).ToString();
                case "Surinam":
                    return gmt.AddMinutes(-180).ToString();
                case "Swaziland":
                    return gmt.AddMinutes(120).ToString();
                case "Sweden":
                    return gmt.AddMinutes(60).ToString();
                case "Switzerland":
                    return gmt.AddMinutes(60).ToString();
                case "Syria":
                    return gmt.AddMinutes(120).ToString();
                case "Taiwan":
                    return gmt.AddMinutes(480).ToString();
                case "Tajikistan":
                    return gmt.AddMinutes(300).ToString();
                case "Tanzania":
                    return gmt.AddMinutes(180).ToString();
                case "Thailand":
                    return gmt.AddMinutes(420).ToString();
                case "Tonga":
                    return gmt.AddMinutes(0).ToString();
                case "Trinidad & Tobago":
                    return gmt.AddMinutes(-240).ToString();
                case "Tunisia":
                    return gmt.AddMinutes(60).ToString();
                case "Turkmenistan":
                    return gmt.AddMinutes(300).ToString();
                case "Turks & Caicos Islands":
                    return gmt.AddMinutes(-240).ToString();
                case "Tuvalu":
                    return gmt.AddMinutes(720).ToString();
                case "Uganda":
                    return gmt.AddMinutes(180).ToString();
                case "Ukraine":
                    return gmt.AddMinutes(120).ToString();
                case "Uruguay":
                    return gmt.AddMinutes(-180).ToString();
                case "USA":
                    return gmt.AddMinutes(-480).ToString();
                case "Uzbekistan":
                    return gmt.AddMinutes(300).ToString();
                case "Vanuatu":
                    return gmt.AddMinutes(660).ToString();
                case "Venezuela":
                    return gmt.AddMinutes(-240).ToString();
                case "Vietnam":
                    return gmt.AddMinutes(420).ToString();
                case "Wallis & Futuna Islands":
                    return gmt.AddMinutes(720).ToString();
                case "Yemen":
                    return gmt.AddMinutes(180).ToString();
                case "Zambia":
                    return gmt.AddMinutes(120).ToString();
                case "Zimbabwe":
                    return gmt.AddMinutes(120).ToString();
                default:
                    return "";
            }
        }


        private void ca_Checked(object sender, RoutedEventArgs e)
        {

            obj_newListForum.Clear();
            url = "http://www.lyonmag.com/win8/get_wires_by_category/44";
            get_filedata();
        }

    }
}